<template>
	<view class="main_container">
		<nav-bar :titleName="'充值'" :backUrl="'/pages/me/index'" style=" position: sticky;top: 0;z-index: 99;"></nav-bar>

		<view class="reCharge_cont">
			<view class="tabs_header">
				<view class="tab_item fl-center" :class="tabIndex == 1 ? 'tabActive1' : ''" @click="tabIndex = 0">
					<view class="">
						客资余额
					</view>
				</view>
				<view class="tab_item fl-center" :class="tabIndex == 0 ? 'tabActive2' : ''" @click="tabIndex = 1">
					<view class="">
						成交余额
					</view>
				</view>
			</view>

			<view class="reCharge_body">
				<view class="kzye" v-if="tabIndex == 0">
					<view class="reCTitle">
						客资框架选购
					</view>

					<view class="jdType_form">
						<view class="jd_radioGroup">
							<u-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
								<u-radio v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.name"
									@change="radioChange">
								</u-radio>
							</u-radio-group>
						</view>
						<view class="bj_list">
							<view class="bj_input_item fl-center" v-for="(item,index) in bj_list" :key="index">
								{{ item.bjValue }}
							</view>
						</view>
					</view>

					<view class="tip">
						<view class="tip_title">
							充值说明：
						</view>
						<view class="tip_content">
							<p>
								1.成功充值后 充值金额会对应到您的账户余额；
								2.选择或支付过程中，遇到任何问题请及时与我们联系<br /><br /><br /></p>
						</view>
						<view class="tip_title">
							关于发票：
						</view>
						<view class="tip_content">
							<span>
								如需开发票请与我们联系，微信/电话：</span>
							<span style="font-weight: 700;color: #000000;">13772186260</span>
						</view>
					</view>
				</view>

				<view class="ddcz" v-if="tabIndex == 1">
					<view class="reCTitle">
						订单佣金充值
					</view>

					<view class="cz_form">
						<view class="cz_list">
							<view class="cz_item fl-center" v-for="(item,index) in cz_list" :key="index" @click="changeCz(item,index)" :class="czIndex == index ? 'czActive' : ''">
								<view class="" v-if="index !== 4" @click="chooseCZ(item,index)">
									{{ item.czValue }}元
								</view>
								<view class="" v-if="index == 4" @click="chooseCZ(item,index)">
									{{ item.czValue }}
								</view>
							</view>
								<view class="cz_input" v-if="showInput">
									<u--input
									    placeholder="请输入充值金额"
									    border="surround"
									    v-model="czIptVal"
									    @change="czChange" style="width: 280rpx;margin-top: -50rpx;"
									  ></u--input>
								</view>
						</view>
					</view>

					<view class="tip">
						<view class="tip_title">
							充值说明：
						</view>
						<view class="tip_content">
							<p>
								1.成功充值后 充值金额会对应到您的账户余额；
								2.选择或支付过程中，遇到任何问题请及时与我们联系<br /><br /><br /></p>
						</view>
						<view class="tip_title">
							关于发票：
						</view>
						<view class="tip_content">
							<span>
								如需开发票请与我们联系，微信/电话：</span>
							<span style="font-weight: 700;color: #000000;">13772186260</span>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="payNow fl-center">
			<view class="pay_btn fl-center" @click="payFor">
				<view class="">
					立即支付
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import navBar from '@/components/navBar/navBar.vue';
	export default {
		components: {
			navBar,
		},
		data() {
			return {
				tabIndex: 0,
				bj_list: [{
					bjValue: '3800个有效客户'
				}, {
					bjValue: '1200个有效客户'
				}, {
					bjValue: '600个有效客户'
				}, {
					bjValue: '150个有效客户'
				}, ],
				cz_list: [{
						czValue: '10000'
					}, {
						czValue: '20000'
					}, {
						czValue: '30000'
					}, {
						czValue: '50000'
					},
					{
						czValue: '其他'
					},
				],
				radiolist1: [{
						name: '超大框：99999元',
						disabled: false
					},
					{
						name: '大框：49999元',
						disabled: false
					},
					{
						name: '中框：29999元',
						disabled: false
					}, {
						name: '体验框：9999元',
						disabled: false
					}
				],
				radiovalue1: '',
				moneyVal1: null,
				czIndex: null,
				showInput: false,
				czIptVal: '',
			};
		},
		methods: {
			groupChange(n) {
				// console.log('groupChange', n);
			},
			radioChange(n) {
				this.radiovalue1 = n
				this.moneyVal1 = this.radiovalue1.match(/\d+/)[0];
				console.log(this.moneyVal1)
			},
			
			changeCz(item,index) {
				this.czIndex = index
			},
			czChange() {
					this.moneyVal1 = this.czIptVal
				console.log(this.moneyVal1)
			},
			chooseCZ(item,index) {
				if(index == 4) {
					this.showInput = true
				} else {
					this.showInput = false
					this.moneyVal1 = item.czValue
				}
				console.log(this.moneyVal1)
			},
			payFor() {
				var that = this;
				// if(that.yuan_xiabiao!==5){
				// 	that.content=that.yuan[that.yuan_xiabiao].money
				// }
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes);
						that.configure.ajax({
							url: 'wxPay/miniAppPay',
							tishi: 1,
							zhuang: 1,
							data: {
								typeid: that.tabIndex,
								code: loginRes.code,
								money: that.moneyVal1
							},
							method: 'POST',
							success: function(res) {
								console.log('res_res')
								console.log(res)
								// paypost=json res.data
								// appId: "wxf0bb3c986a8033a9"
								// nonceStr: "1663865501849"
								// package: "prepay_id=wx230051417294758bd3ee97764bf27d0000"
								// paySign: "FE05EB70DDC13D8D9FEA73B33F3A46FC68F7DCEF0EEF9B3C79B30DD558CAFC7F"
								// signType: "HMAC-SHA256"
								// timeStamp: "1663865501"
								
								// timeStamp: res.data.timeStamp,
								// nonceStr: res.data.nonceStr,
								// package: res.data.package,
								// signType: res.data.signType,
								// paySign: res.data.paySign,
								uni.requestPayment({
									provider: 'wxpay',
									...res.data,
									success: function(res) {
										console.log('success:' + JSON.stringify(res));
										// setTimeout(() => {
										// 	uni.navigateBack();
										// }, 500);
										uni.navigateBack();
									},
									fail: function(err) {
										console.log('fail:' + JSON.stringify(err));
									}
								});
							}
						})
					}
				});
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fl-center {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.main_container {
		width: 750rpx;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100vh;
		padding-bottom: 200rpx;
	}

	.reCharge_cont {
		width: 690rpx;
		// height: 1000rpx;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		border: 1rpx solid #FE609D;
		margin: 63rpx auto 0;
		display: flex;
		flex-direction: column;
	}

	.payNow {
		width: 750rpx;
		height: 120rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;

		.pay_btn {
			width: 630rpx;
			height: 80rpx;
			background: #FE609D;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}

	.tabs_header {
		display: flex;
		align-items: center;
		width: 100%;
		height: 70rpx;

		.tab_item {
			width: 50%;
			height: 70rpx;
			font-size: 30rpx;
			color: #FE609D;
		}
	}

	.tabActive1 {
		background: url(../../static/other/tab2.png) no-repeat;
		background-size: 100% 100%;
		font-size: 26rpx !important;
		color: #FFFFFF !important;
	}

	.tabActive2 {
		background: url(../../static/other/tab1.png) no-repeat;
		background-size: 100% 100%;
		font-size: 26rpx !important;
		color: #FFFFFF !important;
	}

	.reCharge_body {
		width: 100%;
		flex: 1;
		padding: 50rpx 30rpx 40rpx;
		box-sizing: border-box;
	}

	.kzye {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.ddcz {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.reCTitle {
		font-size: 34rpx;
		color: #000000;
		font-weight: 600;
		margin-bottom: 37rpx;
	}

	.jdType_form {
		width: 630rpx;
		// height: 811rpx;
		// background: #F6F6F6;
		margin: 0 auto;
		// padding: 30rpx;
		// box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.jd_radioGroup {
		width: 50%;
		height: 100%;

	}

	.bj_list {
		width: 50%;
		height: 100%;
		font-size: 14px;

		.bj_input_item {
			width: 100%;
			height: 100rpx;
			margin-bottom: 30rpx;
		}
	}

	/deep/ .u-radio {
		height: 100rpx !important;
		margin-bottom: 30rpx !important;
	}

	.tip {
		display: flex;
		flex-direction: column;

		.tip_title {
			font-weight: 700;
			font-size: 24rpx;
			color: #000000;
			margin-bottom: 10rpx;
		}

		.tip_content {
			font-weight: 400;
			font-size: 24rpx;
			color: #797979;
		}
	}
	
	.cz_form {
		width: 620rpx;
		// height: 300rpx;
		.cz_list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			align-items: center;
		}
		
	}
	.cz_item {
		width: 283rpx;
		height: 71rpx;
		background: #FFFFFF;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
		border: 1rpx solid #D0D0D0;
		font-size: 28rpx;
		color: #000000;
		margin-bottom: 40rpx;
	}
	.czActive {
		background-color: #FE609D!important;
		color: #FFFFFF!important;
	}
</style>